package org.shijiagen.product.listener;

import lombok.RequiredArgsConstructor;
import org.shijiagen.product.service.ProductService;
import org.shijiagen.to.OrderToProduct;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class ProductRabbitListener {

    private final ProductService productService;

    /**
     * 减少商品库存数量
     * @param orderToProduct
     */
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "sub.queue"),
                    exchange = @Exchange("topic.ex"),
                    key = "sub.number"
            )
    )
    public void subNumber(List<OrderToProduct> orderToProduct){
        productService.subNumber(orderToProduct);
    }
}
